﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class EventSection : BodiedDeclaration
{
    private StringLiteral? _description;

    internal EventSection(SyntaxToken declareKeywordToken, Identifier name, SyntaxNode? parent) :
        base(SyntaxKinds.EventSection, declareKeywordToken, name, parent)
    {
    }

    public StringLiteral? Description => _description;


    public void Update(StringLiteral description)
    {
        SetChildNullableField(ref _description, Expression.IsEmptyExpression, description);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier, Description, Body);
    }
}


public static partial class NodeFactory
{
    public static EventSection CreateEventSection(SyntaxNode? parent, SyntaxToken declareKeywordToken,
        Identifier identifierName, StringLiteral? description)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.EventKeywordToken));
        EventSection section = new(declareKeywordToken, identifierName, parent);
        if (description != null)
        {
            section.Update(description);
        }

        return section;
    }
}